from django.shortcuts import render_to_response
from unicom.xiaoqu.models import Xiangmu
import xlrd

def xiangmu_list(request):
 xiangmu_list = Xiangmu.objects.all()
 return render_to_response('xiangmu_list.html',{'xiangmu_list':xiangmu_list})

def xiangmu(request):
 return render_to_response('xiangmu_view.html')


def build_data(request):
 xls = xlrd.open_workbook("./static/upload/test.xls")
 sheet = xls.sheet_by_index(0)
 n = sheet.nrows
 i=2
 while i<n:
   xiangmu = Xiangmu(xiaoquming=sheet.cell_value(rowx=i,colx=3), fengongsi=sheet.cell_value(rowx=i,colx=1), zhenqu=sheet.cell_value(rowx=i,colx=2), xuanzhidanwei=sheet.cell_value(rowx=i,colx=13), hetongzhuangtai=sheet.cell_value(rowx=i,colx=15), zulinjieguo=sheet.cell_value(rowx=i,colx=17), wuyezhuangtai=sheet.cell_value(rowx=i,colx=20), zujinbiaozhun=(sheet.cell_value(rowx=i,colx=37) if sheet.cell_value(rowx=i,colx=37)!="" else None), zhongyaoleibie=sheet.cell_value(rowx=i,colx=50), jingdu=sheet.cell_value(rowx=i,colx=51), weidu=sheet.cell_value(rowx=i,colx=52), xianchanghuanjing=sheet.cell_value(rowx=i,colx=53), xiaoqujianshefangshi=sheet.cell_value(rowx=i,colx=47), jifangjianshefangshi=sheet.cell_value(rowx=i,colx=55), shiwaitianxian=sheet.cell_value(rowx=i,colx=56))
   xiangmu.save()
   i+=1
 return render_to_response('build_success.html')
